let app = getApp();

Page({
    /**
     * 页面的初始数据
     */
    data: {
        loading: app.globalData.loading
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (op) {
        let _this = this;
        app.setAppSystem(_this), app.userLogin;
        console.log(op);
        _this.getDetail(op);
        
    },
    getDetail: function (op){
        var _this = this,
            id = op.id;
        var e = wx.getStorageSync("users").id;
        null != op.type ? o.setData({
            post_info_id: op.my_post
        }) : null != op.scene ? _this.setData({
            user_id: e,
            post_info_id: op.scene,
            user_name: wx.getStorageSync("users").name
        }) : _this.setData({
            user_id: e,
            post_info_id: op.id,
            user_name: wx.getStorageSync("users").name
        });
        let d = _this.data.post_info_id;
        app.hyy.request({
            url: "entry/wxapp/IsCollection",
            cachetime: "0",
            data: {
                information_id: d,
                user_id: _this.data.user_id
            },
            success: function (t) {
                1 == t.data ? _this.setData({
                    Collection: !0
                }) : _this.setData({
                    Collection: !1
                });
            }
        }),
        app.hyy.request({
            url: "entry/wxapp/PostInfo",
            cachetime: "0",
            data: {
                id: id
            },
            success: function (t) {
                if (!t.data.tz){
                    _this.showModal("Image");
                    return;
                }else {
                    _this.setData({ showPage: 1 });
                }
                if (null == t.data.tz.type2_name) var e = "";
                else e = t.data.tz.type2_name;
                wx.setNavigationBarTitle({
                    title: t.data.tz.type_name + " " + e
                });
                var a = app.ormatDate(t.data.tz.sh_time);
                for (var o in t.data.tz.time2 = a.slice(0, 16), t.data.pl) t.data.pl[o].time = app.ormatDate(t.data.pl[o].time),
                    t.data.pl[o].time = t.data.pl[o].time.slice(0, 16);
                var i = t.data.tz.givelike;
                for (var n in t.data.tz.img = t.data.tz.img.split(","), t.data.label) t.data.label[n].number = "rgb(" + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + "," + Math.floor(255 * Math.random()) + ")";
                var s = Number(t.data.tz.hb_num),
                    r = Number(t.data.tz.hb_random);
                Number(t.data.tz.hb_type);
                t.data.tz.hb_money = 1 == r ? t.data.tz.hb_money : (Number(t.data.tz.hb_money) * s).toFixed(2),t.data.tz.details = t.data.tz.details.replace("↵", "\n"), t.data.tz.trans1 = 1,
                    t.data.tz.trans2 = 1, t.data.tz.dis1 = "block", t.data.tz.trans_1 = 2, t.data.tz.trans_2 = 1,
                    _this.setData({
                        post: t.data.tz,
                        dianzan: t.data.dz,
                        givelike: i,
                        post_info_id: d,
                        tei_id: t.data.tz.id,
                        criticism: t.data.pl,
                        label: t.data.label
                    });
            
                _this.setData({ loading: false });
            }
        });
        
    },
    showModal(e) {
        this.setData({
            modalName: e
        })
    },
    hideModal(e) {
        this.setData({
            modalName: null
        });
        wx.navigateBack({
            delta: 1
        })
    },
    comment: function (t) {
        var e = this,
            a = wx.getStorageSync("users").id;
        app.hyy.request({
            url: "entry/wxapp/GetUserInfo",
            cachetime: "0",
            data: {
                user_id: a
            },
            success: function (t) {
                1 == t.data.state ? e.setData({
                    comment: !0
                }) : wx.showModal({
                    title: "提示",
                    content: "您的账号异常，请尽快联系管理员",
                    showCancel: !0,
                    cancelText: "取消",
                    confirmText: "确定",
                    success: function (t) { },
                    fail: function (t) { },
                    complete: function (t) { }
                });
            }
        });
    },
    complete: function (t) {
        this.setData({
            complete: t.detail.value
        });
    },
    formid_one: function (t) {
        app.hyy.request({
            url: "entry/wxapp/SaveFormid",
            cachetime: "0",
            data: {
                user_id: wx.getStorageSync("users").id,
                form_id: t.detail.formId,
                openid: wx.getStorageSync("openid")
            },
            success: function (t) { }
        });
        this.setData({
            reply: !1,
            comment: !1,
            replyhf: !1
        });
    },
    formid_two: function (t) {
        app.hyy.request({
            url: "entry/wxapp/SaveFormid",
            cachetime: "0",
            data: {
                user_id: wx.getStorageSync("users").id,
                form_id: t.detail.formId,
                openid: wx.getStorageSync("openid")
            },
            success: function (t) { }
        });
        var e = this,
            a = (t.detail.formId, e.data.complete),
            o = e.data.user_id,
            i = e.data.post_info_id;
        e.data.post.user_id;
        var n, s, r;
        n = new Date(), s = n.getMonth() + 1, r = n.getDate(), 1 <= s && s <= 9 && (s = "0" + s),
            0 <= r && r <= 9 && (r = "0" + r), n.getFullYear(), n.getHours(), n.getMinutes(),
            n.getSeconds();
        "" == a || null == a ? wx.showToast({
            title: "内容为空",
            icon: "loading",
            duration: 1e3
        }) : (e.setData({
            replay: !1,
            comment: !1,
            complete: ""
        }), app.hyy.request({
            url: "entry/wxapp/Comments",
            cachetime: "0",
            data: {
                information_id: i,
                details: a,
                user_id: o
            },
            success: function (t) {
                "error" != t.data ? (wx.showToast({
                    title: "评论成功"
                }), setTimeout(function () {
                    e.reload();
                }, 1e3)) : wx.showToast({
                    title: "评论失败",
                    icon: "loading"
                });
            }
        }));
    },
    saveFormid: function (t) {
        app.hyy.request({
            url: "entry/wxapp/SaveFormid",
            cachetime: "0",
            data: {
                user_id: wx.getStorageSync("users").id,
                form_id: t.detail.formId
            },
            success: function (t) { }
        });
    },
    formSubmit: function (t) {
        app.hyy.request({
            url: "entry/wxapp/SaveFormid",
            cachetime: "0",
            data: {
                user_id: wx.getStorageSync("users").id,
                form_id: t.detail.formId,
                openid: wx.getStorageSync("openid")
            },
            success: function (t) { }
        });
        var e = t.detail.formId;
        console.log("用户的form——id是" + e), console.log(this.data);
        var a = wx.getStorageSync("openid");
        console.log(a);
        var o = this,
            i = o.data.tei_id,
            n = wx.getStorageSync("users").id,
            s = Number(o.data.givelike);
        o.data.post.user_id;
        app.hyy.request({
            url: "entry/wxapp/Like",
            cachetime: "0",
            data: {
                information_id: i,
                user_id: n
            },
            success: function (t) {
                console.log(t), "1" == t.data && (wx.showToast({
                    title: "点赞成功",
                    duration: 1e3
                }), o.reload(), o.setData({
                    thumbs_ups: !0,
                    thumbs_up: s + 1
                })), "不能重复点赞!" == t.data && (wx.showModal({
                    title: "提示",
                    content: "不能重复点赞",
                    showCancel: !0,
                    cancelText: "取消",
                    confirmText: "确认",
                    success: function (t) { },
                    fail: function (t) { },
                    complete: function (t) { }
                }), o.setData({
                    thumbs_ups: !0
                }));
            }
        });
    },
    collection: function (t) {
        var e = this,
            a = e.data.tei_id,
            o = wx.getStorageSync("users").id;
        app.hyy.request({
            url: "entry/wxapp/Collection",
            cachetime: "0",
            data: {
                information_id: a,
                user_id: o
            },
            success: function (t) {
                1 == t.data ? (e.setData({
                    Collection: !0
                }), wx.showToast({
                    title: "收藏成功",
                    icon: "",
                    image: "",
                    duration: 2e3,
                    mask: !0,
                    success: function (t) { },
                    fail: function (t) { },
                    complete: function (t) { }
                })) : (wx.showToast({
                    title: "取消收藏成功",
                    icon: "fail",
                    image: "",
                    duration: 2e3,
                    mask: !0,
                    success: function (t) { },
                    fail: function (t) { },
                    complete: function (t) { }
                }), e.setData({
                    Collection: !1
                }));
            }
        });
    },
    openshare: function () {
        console.log('点击分享了');
        this.setData({
            share_modal_active: "active"
        });
    },
    showShareModal: function () {
        this.setData({
            share_modal_active: "active"
        });
    },
    shareModalClose: function () {
        this.setData({
            share_modal_active: ""
        });
    },
    canvas: function (t) {
        wx.showToast({
            title: '系统开发中..',
        });
        return;
        wx.navigateTo({
            url: "canvas?proportion=" + this.data.proportion + "&img_height=" + this.data.img_height + "&img_width=" + this.data.width + "&post_info_id=" + this.data.post_info_id + "&qr_code=" + this.data.qr_code
        });
    },
    shouye: function (t) {
        wx.reLaunch({
            url: "/hyy_city/pages/index/index",
            success: function (t) { },
            fail: function (t) { },
            complete: function (t) { }
        });
    },
    image: function (t) {
        if (0 == t.currentTarget.dataset.inde) {
            var e = t.detail.height,
                a = t.detail.width;
            this.setData({
                proportion: e / a,
                img_height: e,
                img_width: a
            });
        }
    },
    reply1: function (t) {
        var e = t.currentTarget.dataset.reflex_id,
            a = t.currentTarget.dataset.name;
        this.data.user_id, this.data.post.user_id;
        this.setData({
            reply: !0,
            reflex_id: e,
            reflex_name: "回复" + a
        });
    },
    reply3: function (t) {
        var e = this,
            a = e.data.user_id,
            o = e.data.post_info_id,
            i = e.data.reflex_id,
            n = e.data.complete1;
        "" == n || null == n ? wx.showToast({
            title: "内容为空",
            icon: "loading",
            duration: 1e3
        }) : (e.setData({
            reply: !1,
            complete1: ""
        }), app.hyy.request({
            url: "entry/wxapp/Comments",
            cachetime: "0",
            data: {
                information_id: o,
                details: n,
                user_id: a,
                bid: i
            },
            success: function (t) {
                "error" != t.data && (wx.showToast({
                    title: "回复成功"
                }), setTimeout(function () {
                    e.reload();
                }, 1e3));
            }
        }));
    },
    openhf: function (t) {
        var e = t.currentTarget.dataset.reflex_id,
            a = t.currentTarget.dataset.name,
            o = t.currentTarget.dataset.hfid;
        this.setData({
            replyhf: !0,
            reflex_id: e,
            hfid: o,
            reflex_name: "回复" + a
        });
    },
    huifu: function (t) {
        var e = this,
            a = e.data.user_id,
            o = e.data.post_info_id,
            i = this.data.hfid,
            n = this.data.reflex_id,
            s = e.data.complete2;
        "" == s || null == s ? wx.showToast({
            title: "内容为空",
            icon: "loading",
            duration: 1e3
        }) : (e.setData({
            replyhf: !1,
            complete2: ""
        }), app.hyy.request({
            url: "entry/wxapp/Comments",
            cachetime: "0",
            data: {
                information_id: o,
                details: s,
                user_id: a,
                bid: n,
                hf_id: i
            },
            success: function (t) {
                "error" != t.data && (wx.showToast({
                    title: "回复成功"
                }), setTimeout(function () {
                    e.reload();
                }, 1e3));
            }
        }));
    },
    phone(t) {
        var e = t.currentTarget.dataset.id;
        wx.makePhoneCall({
            phoneNumber: e
        });
    }
})